package com.william.jdbcplus.core.dialect.fill.impl;

import com.william.jdbcplus.common.entity.Entity;
import com.william.jdbcplus.core.crud.CrudConfig;
import com.william.jdbcplus.core.dialect.fill.IFill;
import com.william.jdbcplus.core.toolkit.SequenceUtil;

import java.util.LinkedList;
import java.util.List;

/**
 * 分布式高效有序填充
 *
 * @author william
 */
public class SequenceFill implements IFill {
    private static SequenceUtil sequenceUtil = new SequenceUtil();

    @Override
    public <M extends Entity> Object getValue(Class<M> entityClass, String fieldName, CrudConfig config) {
        Long nextId = sequenceUtil.nextId();
        return nextId;
    }

    @Override
    public <M extends Entity> List<?> getValueList(Class<M> entityClass, String fieldName, int count, CrudConfig config) {
        List<Long> result = new LinkedList<>();
        for (int i = 1; i <= count; i++) {
            result.add(sequenceUtil.nextId());
        }
        return result;
    }
}
